<template>
    <div>
        <el-row>
            <el-col :span="24">
                <!-- 放搜索条件 -->
                <el-form :inline="true">

                    <el-form-item label="患者姓名">
                        <el-input placeholder="请输入患者姓名" clearable="" v-model="admissionForm.name"></el-input>
                    </el-form-item>
                    <el-form-item label="科室">
                        <el-select v-model="admissionForm.deId" @change="updateDocList" clearable="">
                            <el-option v-for="department in deList" :key="department.id" :label="department.deName"
                                :value="department.id">
                            </el-option>
                        </el-select>

                        <el-select v-model="admissionForm.docId" clearable="">
                            <el-option v-for="doc in docList" :key="doc.id" :label="doc.docName"
                                :value="doc.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="queryList">查询</el-button>
                    </el-form-item>
                </el-form>



            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24">
                <!-- 表格 -->
                <el-table :data="tableData" style="width: 100%">
                    <el-table-column prop="id" label="编号"></el-table-column>
                    <el-table-column prop="name" label="病人姓名"></el-table-column>
                    <el-table-column prop="deName" label="住院科室"></el-table-column>
                    <el-table-column prop="docName" label="申请医生"></el-table-column>
                    <el-table-column prop="iaDate" label="申请日期"></el-table-column>
                    <el-table-column prop="iaStatus" label="状态">
                        <template slot-scope="scope">
                            <el-tag
                                :type="scope.row.iaStatus == '0' ? 'danger' : (scope.row.iaStatus == '1' ? 'primary' : 'success')"
                                disable-transitions>
                                {{ scope.row.iaStatus == '0' ? '未缴费' : (scope.row.iaStatus == '1' ? '待确定' : '已完成') }}
                            </el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column label="操作">
                        <template slot-scope="scope">
                            <el-button type="primary" icon="el-icon-star-off"
                                @click="updateStatus(scope.row)">
                                入院申请
                            </el-button>
                        </template>

                    </el-table-column>
                </el-table>


            </el-col>
        </el-row>
        <el-row>
            <el-col :span="24">
                <!-- 放分页 -->
                <el-pagination background :current-page="pageNum" :page-size="pageSize" @next-click="nextPage"
                    @prev-click="prePage" @current-change="currentPage" @size-change="sizeChange"
                    layout="prev, pager, next,total,sizes" :total="total" :page-sizes="[5, 10, 15, 20]">
                </el-pagination>
            </el-col>
        </el-row>

        <el-dialog title="入院申请" :visible.sync="dialogFormVisible" style="text-align: left;">
            <el-form :model="form">
                <el-form-item label="医生">
                        <el-input  :value="`${doc.docName} - ${doc.deName}`"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="agreeAddmission">确 定</el-button>
            </div>
        </el-dialog>

    </div>

</template>

<script>
export default {
    data() {
        return {
            tableData: [],
            pageNum: 1,
            pageSize: 5,
            total: 0,
            doc:{},
            addmission:{},//入院申请
            admissionForm: {
                ptId:'',
                name: "",
                deId: "",
                docId: "",
                iaStatus: "1",
            },
            statusList: [
                { id: 0, name: '未缴费' },
                { id: 1, name: '待确定' },
                { id: 2, name: '已完成' },

            ],
            docList:[],
            deList: [
                {
                    id: "",
                    docName: "",
                    docList: [
                        // { docId: "1", docName: "tom" },
                    ]
                }],
            form: {
                docId:'',
            },
            dialogFormVisible: false,
        }
    },
    methods: {
        nextPage(val) {
            //用户点击下一页触发
            this.pageNum = val;
            this.queryList();
        },
        prePage(val) {
            //上一页
            this.pageNum = val;
            this.queryList();
        },
        currentPage(val) {
            //当前页
            this.pageNum = val;
            this.queryList();
        },
        sizeChange(val) {
            this.pageNum = 1
            this.pageSize = val;
            this.queryList();
        },
        queryList() {

            let pageparam = {}
            pageparam.pageNum = this.pageNum
            pageparam.pageSize = this.pageSize
            pageparam.param = this.admissionForm

            this.$axios.post("api/form/querylist", pageparam)
                .then(res => {
                    if (res.data.code == 200) {
                        this.pageNum = res.data.data.pageNum
                        this.pageSize = res.data.data.pageSize
                        this.total = res.data.data.total
                        this.tableData = res.data.data.list
                        console.log(this.tableData)

                    }

                })
        },
        queryDe() {
            this.$axios.get("api/form/queryde")
                .then(res => {
                    if (res.data.code == 200) {
                        this.deList = res.data.data
                    }
                })
        },
         //查找医生信息
        queryDoctor(){
        this.$axios.get("api/doctor/queryDoctor")
        .then(res=>{
            if(res.data.code==200){
                this.doc=res.data.data;
            }
        })
        },
        updateDocList() {
            const selectedDe = this.deList.find(department => department.id === this.admissionForm.deId);
            this.docList = selectedDe ? selectedDe.docList : [];
        },
        //同意住院申请
        updateStatus(val){
            this.dialogFormVisible=true
            this.addmission=val
            console.log(val)
        },
        //同意住院申请
        agreeAddmission(){
            if(this.addmission.iaStatus!=1){
                this.$message.warning("当前申请已失效")
                return;
            }
            this.addmission.status=0
            this.$axios.post('api/form/updateAF',this.addmission)
            .then(res=>{
                if(res.data.code==200){
                    this.$message.success("您已同意入院申请")
                }
            })
        }

    },
    created() {
        this.queryList()
        this.queryDe()
        this.queryDoctor()
    }

}
</script>

<style scoped></style>